package com.jwell.panprovider.ui.fragment.waybillinfo


import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.jwell.panprovider.R
import com.jwell.panprovider.entity.ForWaybillLogListDto
import com.jwell.panprovider.entity.WaybillInfoBean
import com.jwell.panprovider.tools.StringUtils
import com.jwell.panprovider.ui.activity.WaybillInfoActivity
import com.jwell.panprovider.ui.adapter.WaybillInfoLogAdapter
import kotlinx.android.synthetic.main.fragment_basic_info.*


/**
 * A simple [Fragment] subclass.
 * 运单基本信息
 */
class BasicInfoFragment constructor() : Fragment() {
    private var logList = ArrayList<ForWaybillLogListDto>()
    private var adapter = WaybillInfoLogAdapter(logList)
    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        var view = inflater!!.inflate(R.layout.fragment_basic_info, container, false)
        initData()
        return view
    }

    private fun initData() {
        var activity = activity as WaybillInfoActivity
        activity.setListener(object : WaybillInfoActivity.DataListener {
            override fun setData(data: WaybillInfoBean) {
                data.let {
                    text_jh_code.text = it.planCode ?: ""
                    if (it.planDate != null) {
                        text_time.text = StringUtils.getInstance()
                                .setModal(StringUtils.TIME_TYPE_1)
                                .regularization(it.planDate, "T", " ")
                    } else {
                        text_time.text = ""
                    }
                    text_sendCom.text = it.forwardingUnit ?: ""
                    text_receiptCom.text = it.receivingUnit ?: ""
                    text_contractNum.text = it.mtrlOrderNo ?: ""
                    text_waybill_code.text = it.forBillCode ?: ""
                    text_driverInfo.text = (it.driverName ?: "") + "/" + (it.driverPhone ?: "")
                    text_carNum.text = it.carNum ?: ""
                    text_goodsName.text = it.materialName ?: ""
                    text_provide_carNum.text = (it.netWt).toString() + "吨"
                    text_provide_carNum.text = (it.netWt).toString() + "吨"
                    text_remark.text = it.remark ?: "无"
                    logList.clear()
                    logList.addAll(it.waybillLog)
                    recyclerView.adapter = adapter
                    recyclerView.layoutManager = LinearLayoutManager(context)
                }
            }
        })
    }
}
